//
//  SNShopPageDataManager.m
//  app
//
//  Created by 王少宁 on 15/6/29.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "SNShopPageDataManager.h"
#import "SNFmdbManager.h"

@interface SNShopPageDataManager ()
@property (nonatomic, retain) SNShopPageHttpResult * result;
@property (nonatomic, retain) JKHttpClient * http;
@end

@implementation SNShopPageDataManager

- (instancetype)initWithResult:(SNShopPageHttpResult *)result
{
    if ([super init]) {
        self.result = result;
        self.http = [[JKHttpClient alloc] init];
    }
    return self;
}

#pragma mark - 从网络加载首页数据
- (void)loadShopPageDataWithUrl:(NSString *)url withMyareaId:(NSString *)myareaId
{
    if ([self.http isRunning]) {
        return;
    }
    
    self.result.success = NO;
    
    NSDictionary * parm = @{@"cmid":myareaId} ;
    
    [self.http get:url params:parm result:^(JKResponse *resp) {
        
        [self.http showNetUnReachableToast];
        
        if (resp.OK) {
//            DLog(@"%@",resp.request.URL);
//            DLog(@"%@",resp.content);
            
            DLog(@"活动url======%@",resp.content[@"message_url"]);
            
            if (resp.success) {
                
                [[NSUserDefaults standardUserDefaults]setObject:resp.content[@"message_url"] forKey:@"huodong_url"];
                [[NSUserDefaults standardUserDefaults]synchronize];
                
                
                [[SNBaseInfoManager shareManager] setBaseInfoObject:myareaId forKey:kLastRequestMainPageCmid];
                self.result.success = YES;
                self.result.shopModel = [SNShopModel modelWithDict:resp.content];
                
            } else if (resp.failure) {
                self.result.success = NO;
            }
            
        }
       
        [self.result invoke];
        
    }];
    
}

@end





